import axios from 'axios'

const TEST_URL = 'http://10.108.37.53:8000'
const CUR_URL = TEST_URL

const client = axios.create({
  baseURL: CUR_URL,
  timeout: 1000,
  headers: {
    Authorization: `${window.localStorage.getItem('token')}`,
  },
})

client.interceptors.request.use(
  (req) => {
    return req
  },
  (err) => {
    return Promise.reject(err)
  }
)

client.interceptors.response.use(
  (req) => {
    return req
  },
  (err) => {
    return Promise.reject(err)
  }
)

async function request (url, config) {
  const response = await client.request({ url, ...config })
  const result = response.data
  return result
}

export { request }
